<?php
/**
 * 用户账号信息
 * User: minyifei.cn
 * Date: 15/7/8
  数据库表结构
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`number` bigint(20) DEFAULT NULL COMMENT '用户编号',
`mobile` varchar(20) NOT NULL COMMENT '手机号',
`password` varchar(50) NOT NULL COMMENT '编码后密码',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `mobile` (`mobile`),
UNIQUE KEY `number` (`number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表'
 */

namespace MyfApi\Model;

use MyfApi\Libs\SequenceNumber;

class User extends \Myf\Mvc\Model {

    /**
     * 创建用户
     * @param $mobile
     * @param $password
     * @return string
     */
    public static function create($mobile,$password){
        $now = getCurrentTime();
        //创建用户
        $d = array(
            "mobile"=>$mobile,
            "password"=>encodePassword($password),
            "create_time"=>$now,
            "update_time"=>$now,
        );
        $m = new self();
        $id = $m->save($d);
        $number = SequenceNumber::generateNumber($id);
        $ud = array(
            "number"=>$number,
        );
        $m->update($ud,"id=:id",array("id"=>$id));
        $d["number"]=$number;
        $d["token"] = UserToken::getToken($id);
        unset($d["password"]);
        return $d;
    }

}